package com.leolian.spring02.transaction.demo1;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @author Lian
 * Service实现类
 */
@Service("accountService")
public class AccountServiceImpl implements AccountService {
	
	@Autowired
	private AccountDao accountDao;
	@Resource
	private TransactionTemplate transactionTemplate;
	
	public void transfer(final String out,final String in,final Double money) {
		
		transactionTemplate.execute(new TransactionCallbackWithoutResult(){
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				accountDao.decrMoney(out, money);
				int i = 1 / 0;
				accountDao.incrMoney(in, money);
			}
		});
	}

}
